#include<iostream>
#include<cstring>
using namespace std;
struct StudentInfo {
    string name;
    string sid;
    short score;
};
int main()
{
    int n,min=0,max=0,maxindex=0,minindex=0;
    string Name;
	string SId;
	int Score;
    scanf("%d",&n);
	StudentInfo stu[n];
	for(int i=0;i<n;i++)
	{
		cin>>Name>>SId>>Score;
		stu[i].name=Name;
		stu[i].sid=SId;
		stu[i].score=Score;
		if(i==0) min=Score;
		if(Score>max){
			max=Score;
			maxindex=i;
		}
		if(Score<min){
			min=Score;
			minindex=i;
		}
	}
	cout<<stu[maxindex].name<<" "<<stu[maxindex].sid<<endl<<stu[minindex].name<<" "<<stu[minindex].sid;
    return 0;
}
